home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / 076-100 / scopedisk87 / runback4 / null.src / null.c < prev   
Encoding:
C/C++ Source or Header  |  1995-03-19  |  3.0 KB  |  102 lines

  1. /****************************************************************************
  2.  *
  3.  *  null driver V0.0 (c)CopyRight 1988, Gunnar Nordmark.  All Rights Reserved.
  4.  *
  5.  *  null-handler Ver. 0.0  20-Jul-1988
  6.  *
  7.  *  Gunnar Nordmark
  8.  *  Nora strand 5
  9.  *  182 34 DANDERYD
  10.  *  SWEDEN
  11.  *
  12.  *  |You may freely distribute this source as long as |
  13.  *  |the Copyright notice is left intact.             |
  14.  ***************************************************************************/
  15.  
  16. #undef  BADDR
  17. #define BADDR(x)   ((APTR)((long)x << 2))
  18.  
  19. #define ACTION_FINDINPUT        1005L
  20. #define ACTION_FINDOUTPUT       1006L
  21. #define ACTION_END              1007L
  22.  
  23. #define DOS_FALSE               0L
  24. #define DOS_TRUE               -1L
  25.  
  26. /* My Globals */
  27.  
  28. long                SysBase;
  29. struct Process      *myproc;
  30.  
  31. _main()
  32. {
  33.     extern void returnpkt();            /* sends back the packet          */
  34.     extern void returnpktplain();       /* use args in Res1               */
  35.     extern struct DosPacket *taskwait();
  36.  
  37.            char       *version =        "Ver 0.0 (c) Gunnar Nordmark 1988";
  38.     struct DosPacket  *mypkt;           /* a pointer to the dos packet    */
  39.     struct DeviceNode *mynode;          /* our device node (parmpkt Arg3) */
  40.     struct FileHandle *fh;              /* a pointer to our file handle   */
  41.     long              run = TRUE;       /* handler main loop flag         */
  42.     int               null_open = 0;    /* null open count                */
  43.  
  44.  
  45.         /* Initializing the handler */
  46.  
  47.     myproc      = (struct Process *)FindTask(0L);
  48.     mypkt       = taskwait(myproc);      /* Wait for my startup message */
  49.  
  50.         /* I don't need the name or extra info passed in Arg1/2 */
  51.  
  52.     mynode              = (struct DeviceNode *)BADDR(mypkt->dp_Arg3);
  53.     mynode->dn_Task     = &myproc->pr_MsgPort;
  54.     returnpkt(mypkt, myproc, DOS_TRUE, mypkt->dp_Res2);
  55.  
  56.         /* done initial stuff, now for some work */
  57.  
  58.     while(run) {
  59.         mypkt = taskwait(myproc);
  60.  
  61.         switch(mypkt->dp_Type) {        /* find what action to perform */
  62.  
  63.         case ACTION_FINDINPUT:
  64.         case ACTION_FINDOUTPUT:
  65.  
  66.             null_open++;
  67.  
  68.             fh = (struct FileHandle  *)BADDR(mypkt->dp_Arg1);
  69.             fh->fh_Arg1 = mypkt->dp_Type;
  70.             fh->fh_Port = (struct MsgPort *)DOS_FALSE; /* not interactive */
  71.  
  72.             returnpkt(mypkt, myproc, DOS_TRUE, mypkt->dp_Res2);
  73.             break;
  74.  
  75.         case ACTION_READ:
  76.  
  77.             returnpkt(mypkt, myproc, 0, mypkt->dp_Res2); /* zero-length=EOF */
  78.             break;
  79.  
  80.         case ACTION_WRITE:
  81.  
  82.             mypkt->dp_Res1 = mypkt->dp_Arg3;  /* tell em we wrote them all */
  83.             returnpktplain(mypkt, myproc);
  84.             break;
  85.  
  86.         case ACTION_END:
  87.  
  88.             if (--null_open == 0)
  89.                 run = 0;
  90.  
  91.             returnpkt(mypkt, myproc, DOS_TRUE, mypkt->dp_Res2);
  92.             break;
  93.  
  94.         default:
  95.  
  96.             returnpkt(mypkt, myproc, DOS_FALSE, ERROR_ACTION_NOT_KNOWN);
  97.             break;
  98.         }
  99.     } /* end while */
  100.     mynode->dn_Task = FALSE;
  101. }
  102.